<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<base th:href="@{/}" />
<title>Insert title here</title>
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/Managerstyle.css" />
<style>
	
</style>
</head>
<body>
	<div sec:authorize="hasRole('teacher')" class="contain">
		<h3>修改密码</h3>
		<div class="modify">
			<form  method="post">
				<dl class="dl-horizontal">
					<dt>请输入原密码：</dt>
					<dd><input type="text" id="oldPassword" name="oldPassword" class="form-control" style="width: 250px;"></dd>
					<br>
					<dt>请输入新密码：</dt>
					<dd><input type="password" id="newPassword" name="newPassword" class="form-control" style="width: 250px;"></dd>
					<br>
				</dl>
				<button id="button" type="button" class="btn btn-primary" style="margin-bottom: 10px; margin-top: -20px;" >提 交</button>
				<a id="logout" onclick="parent.location.href='logout'"></a><br />
				<span id="msg" style="color: red;"></span>
			</form>
		</div>
	</div>
	<div sec:authorize="hasRole('student')" class="contain">
		<h3>修改密码</h3>
		<div class="modify">
			<form  method="post">
				<dl class="dl-horizontal">
					<dt>请输入原密码：</dt>
					<dd><input type="text" id="oldPassword2" name="oldPassword" class="form-control" style="width: 250px;"></dd>
					<br>
					<dt>请输入新密码：</dt>
					<dd><input type="password" id="newPassword2" name="newPassword" class="form-control" style="width: 250px;"></dd>
					<br>
				</dl>
				<button id="button2" type="button" class="btn btn-primary" style="margin-bottom: 10px; margin-top: -20px;" >提 交</button>
				<a id="logout2" onclick="parent.location.href='logout'"></a><br />
				<span id="msg2" style="color: red;"></span>
			</form>
		</div>
	</div>
	<script>
	 
		$(document).ready(function(){
			$("#button").click(function(){
				$.ajax({
					url: "teach/teacherModifyPassword",
					type: "POST",
					data: {oldPassword:$("#oldPassword").val(),newPassword:$("#newPassword").val()},
					success:function(data){
						if(data == true){
							$("#msg").html("修改成功，将于2S后退出");
							setTimeout(function(){ $("#logout").click(); }, 2000);
							
						}else{
							$("#msg").html("原密码错误");
						}
					},
					error: function(){
						
					}
				});
				
			});
			
			$("#button2").click(function(){
				$.ajax({
					url: "stu/studentModifyPassword",
					type: "POST",
					data: {oldPassword:$("#oldPassword2").val(),newPassword:$("#newPassword2").val()},
					success:function(data){
						if(data == true){
							$("#msg2").html("修改成功，将于2S后退出");
							setTimeout(function(){ $("#logout2").click(); }, 2000);
							
						}else{
							$("#msg2").html("原密码错误");
						}
					},
					error: function(){
						
					}
				});
				
			});
		});
	</script>
</body>
</html>